const express = require('express')
const app = express()
const bodyParser = require('body-parser')
const path = require('path')
const cors = require('cors')
const cookieParser = require('cookie-parser')
const userRouter = require('./router/userRouter')
const sendCodeRouter = require('./router/sendCodeRouter')
const fileRouter = require('./router/fileRouter')
const httpRouter = require('./router/httpRouter')
const webSocketRouter = require('./router/webSocketRouter')
const cityRouter = require('./router/cityRouter')
const resumeRouter = require('./router/resumeRouter')
const db = require('./db/connect')
const {startHttpMonitor} = require('./utils/httpMonitor')
const {startWebSocketMonitor} = require('./utils/webSocketMonitor')

let httpMonitorTimer = null

app.use(cors())
app.use(bodyParser.urlencoded({ extended: false }))
app.use(bodyParser.json())
app.use('/public', express.static(path.join(__dirname, './public')));
app.use(cookieParser())
app.get('/', (req, res) => {
	res.send({ code: 0 })
})

app.use('/user', userRouter)
app.use('/sendCode', sendCodeRouter)
app.use('/file', fileRouter)
app.use('/http', httpRouter)
app.use('/webSocket', webSocketRouter)
app.use('/city', cityRouter)
app.use('/resume', resumeRouter)

// require('./utils/updateCity')

//10分钟http访问一次
// startHttpMonitor(httpMonitorTimer, 1000 * 60 * 10)
// startHttpMonitor(httpMonitorTimer, 1000)

//启动socket监控服务
// startWebSocketMonitor()

console.log('server running http://localhost:11100')
app.listen(11100)